/**
 * Baidu.com Inc.
 * Copyright (c) 2022 All Rights Reserved.
 */
package guaduation.processTemplate;

import guaduation.dataEncapusulation.AbstractEncapusulation;
import guaduation.dataEncapusulation.EncapusulationImpl;
import guaduation.exception.FailException;
import guaduation.service.AbstractNetworkService;
import guaduation.service.RFIDNetworkService;
import guaduation.utils.PropertiesUtil;
import guaduation.vo.CardVO;

import java.util.HashMap;

/**
 * @author wangjiajun06
 * @version 1.0
 * @description
 * @date 2022/1/18 3:38 下午
 */
public class RFIDProcessTemplate extends AbstractProcessTemplate{

    private CardVO cardVO;

    private HashMap<String, String> params;

    @Override
    public void encapusulate(byte[] data) {
        encapusulation = new EncapusulationImpl(data);
        cardVO = (CardVO) this.encapusulation.encapusulation();
    }

    @Override
    public void processData()  throws FailException{
        if (!encapusulation.isSeccess()) {
            throw new FailException();
        }
        params = new HashMap<>();
        params.put("id", cardVO.getId().substring(10, 34));
    }

    @Override
    public void doNetwork() {
        PropertiesUtil.readProperties("RFIDProperties.yaml");
        networkService = new RFIDNetworkService(PropertiesUtil.getProperty("entry"), params);
        networkService.doService();
    }
}
